<template>
  <div class="app-container">
    <!-- 查询条件 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      v-show="showSearch"
      :inline="true"
      @submit.native.prevent
    >
      <el-form-item label="考勤月份" prop="workTime">
        <el-date-picker
          v-model="queryParams.workTime"
          value-format="yyyy-MM"
          type="month"
          placeholder="选择月"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="班组" prop="deptId">
        <el-select
          v-model="queryParams.deptId"
          placeholder="请选择班组信息"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in deptInfo"
            :key="dict.deptId"
            :label="dict.deptName"
            :value="dict.deptId"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="tableData"
    >
      <el-table-column label="序号" type="index" width="100"></el-table-column>
      <el-table-column label="班组" align="center" prop="deptName"/>
      <el-table-column label="考勤月份" align="center" prop="workTime" />
      <el-table-column
        label="操作"
        align="center"
        min-width="200"
        class-name="small-padding fixed-width"
      >
        <template scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 10"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-sizes="[10]"
      @pagination="getTableRecords"
    />

  </div>
</template>

<script>
import {listUserMonthAttendanceSum} from "@/api/job/attendance/attendanceMonth";
import {
  listRole
} from '@/api/job/termSchedule/termSchedule';
import {tableRecords} from "@/api/system/dept";
export default {
  data() {
    return {
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 表单是否可用
      formEnable: true,
      // 每页数量
      total: 10,
      showSearch: true,
      // 提交表单
      formOpen: false,
      // 表格数据选中列表
      multipleSelection: [],
      // 表格记录
      tableData: [],
      groupOptions:[],
      //班组信息
      deptInfo:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workTime: undefined,
        deptId:undefined
      },

    };
  },
  created() {
    this.getTableRecords();
  },
  methods: {
    // 初始化页面
    init() {},
    // 搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getTableRecords();
    },
    // 表单重置
    reset() {},
    // 新增按钮
    handleAdd() {},
    // 删除按钮
    handleDelete() {},
    // 获取表格数据
    getTableRecords() {
      this.loading = true;
      listUserMonthAttendanceSum(this.queryParams).then(response => {

        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.listRole();
    },
    //班组信息
    listRole(){
      tableRecords({category: 2}).then(response => {
        this.deptInfo = response.rows;
      });
    },

    // 详情
    handleView(row) {
      let workTime = row.workTime+"-01";
      let deptName = row.deptName;
      let deptId = row.deptId;
      // this.$router.push({path:"/personnel/attendance/attendanceMonthDetail",query:{workTime:workTime,deptName:deptName,deptId:deptId}});
      this.$router.push({path:"/attendance/attendanceMonthDetail",query:{workTime:workTime,deptName:deptName,deptId:deptId}});
    },
    // 修改
    handleUpdate(row) {},

    // 导出
    // handleExport() {
    //
    //
    // },
    // 重置
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        deptName: null,
        category: null
      };
      this.getTableRecords();
    },
    // 表单提交
    submit() {},
    // 取消
    cancel() {
      this.formOpen = false;
    },
    // 排序控件
    numChange(v) {
    }
  },

};
</script>

<style scoped>
</style>
